package com.exam.controller;

import com.exam.dto.ActionResult;
import com.exam.po.Score;
import com.exam.service.ScoreService;
import com.exam.vo.ScoreVC;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.omg.PortableInterceptor.ACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @ClassName ScoreAdminCpntroller
 * @Description TODO
 * @action luoliang
 * @Data 2021/1/13 14:42
 * @Version 1.0
 */
@RestController
@RequestMapping("/api")
public class ScoreAdminCpntroller {

    @Autowired
    private ScoreService scoreService;

    /**
     * 分页审核成绩
     * @param current
     * @param size
     * @return
     */
    @ApiOperation(value = "分页查询成绩信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "查询的页码", required = true),
            @ApiImplicitParam(name = "size", value = "页面容量", required = true)
    })
    @RequestMapping(value = "/adminfindscore/{current}/{size}",method = RequestMethod.GET)
    @ResponseBody
    public ActionResult FindScoreAdmin(@PathVariable Integer current,@PathVariable Integer size){

        //总记录
        int abc = scoreService.countStudent();
        int abd = scoreService.countScoreVC();
        int count = abc+abd;

        List<ScoreVC> list = scoreService.selectAdminBystudent(current, size);


        HashMap<Object, Object> map = new HashMap<>();
        map.put("data",list);
        map.put("total",count);



        if (map != null){
            ActionResult success = new ActionResult(200, "success", map);
            return success;
        }else {
            ActionResult error = new ActionResult(203, "error", null);
            return error;
        }


    }

    /**
     * 管理员审核成绩
     * @param
     * @return
     */
    @RequestMapping(value = "/adminupdatescore/{scoreid}",method = RequestMethod.PUT)
    @ResponseBody
    public ActionResult UpdateScoreAdmin(@PathVariable Integer scoreid){



        int i = scoreService.updateAdminBySelective(scoreid);
        if (i >-1){
           
            ActionResult success = new ActionResult(200, "success", i);
            return success;
        }else {
            ActionResult error = new ActionResult(203, "error", null);
            return error;
        }
    }
}
